package com.quad.innovators.salesease.enums;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.quad.innovators.salesease.exception.BusinessException;

import java.util.HashMap;
import java.util.Map;

import lombok.Getter;

/**
 * @author : shanshan.li
 * @createTime : 2025/2/8 16:25
 * @Version : 1.0 
 */
@Getter
public enum OrderStatusEnum {
    EXIST(1, "已报单"),
    READY(2, "已备货"),
    SIGNED(3, "已签收"),
    AUDIT(4, "已审核");


    private final int code;
    private final String description;

    OrderStatusEnum(int code, String description) {
        this.code = code;
        this.description = description;
    }

    static final Map<Integer, OrderStatusEnum> map = new HashMap<>();

    static {
        OrderStatusEnum[] values = values();
        for (OrderStatusEnum value : values) {
            map.put(value.code, value);
        }
    }

    public static OrderStatusEnum useCodeGetEnum(Integer code) {
        OrderStatusEnum orderStatusEnum = map.getOrDefault(code, null);
        if (ObjectUtils.isNull(orderStatusEnum)){
            throw BusinessException.resultCode(ResultCode.NOT_FOUND);
        }
        return orderStatusEnum;
    }
}
